<template>
    <div>
        <el-form ref="CustomerForm" :inline="true" :model="CustomerForm" class="tpl-form-inline pb0">
            <el-form-item label="车辆地区">
                <el-select v-model="CustomerForm.region" placeholder="全部">
                </el-select>
            </el-form-item>
            <el-form-item label="车型">
                <el-select v-model="CustomerForm.carType" placeholder="全部">
                    <el-option label="卡罗拉" value="卡罗拉"></el-option>
                    <el-option label="大众" value="大众"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="保险公司">
                <el-select v-model="CustomerForm.safeName" placeholder="全部">
                    <el-option label="阳光保险" value="阳光保险"></el-option>
                    <el-option label="平安保险" value="平安保险"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="起保时间">
                <el-date-picker v-model="date1" type="datetime" placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
        </el-form>
        <div class="mt10 mb20">
            <el-button type="primary" icon="el-icon-search" @click="queryList" :disabled="loading">查询</el-button>
            <el-button @click="reset" icon="el-icon-refresh" :disabled="loading">重置</el-button>
            <el-button type="primary" icon="el-icon-download" @click="exportFile" >导出</el-button>
        </div>

        <div class="text item">
            <el-table class="sd" stripe border :data="tableData" v-loading="loading">
                <el-table-column align="center" prop="index" label="序号" width="100"></el-table-column>
                <el-table-column align="center" prop="date" label="起保时间"></el-table-column>
                <el-table-column align="center" prop="vCode" label="车辆VIN码"></el-table-column>
                <el-table-column align="center" prop="safeType" label="保险类型"></el-table-column>
                <el-table-column align="center" prop="safeName" label="保司"></el-table-column>
                <el-table-column align="center" prop="carType" label="车辆型号"></el-table-column>
                <el-table-column align="center" prop="region" label="所在区域"></el-table-column>
                <el-table-column align="center" prop="status" label="避灾服务状态">
                    <template scope="scope"><span :style="{color: scope.row.status == '已开通' ? '#67C23A': '#F7AB48'}">{{scope.row.status}}</span></template>
                </el-table-column>
            </el-table>
            <el-pagination class="tpl-mg-t mt20 fr"
                            small
                            @size-change="pageSizeChange"
                            @current-change="pageCurrentChange"
                            :current-page="CustomerForm.pageNum"
                            :page-sizes="[10, 20, 30, 40, 50, 100]"
                            :page-size="CustomerForm.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total">
            </el-pagination>
        </div>

    </div>
</template>

<script>
    export default {
        name: 'policyInfo',
        data () {
            return {
                // 查询表单
                CustomerForm: {
                    region: '',
                    carType: '',
                    safeName: '',
                    date1: '',
                },
                // 数据总条数
                total: 0,
                // 表格数据
                tableData: [],
                newData: [],
                params: {},
                date1: '',
                loading: false
            }
        },
        created () {
            this.getList();
        },
        mounted () {
        },
        computed: {
        },
        methods: {
            handleEdit (i,r) {
                this.$routerTo('editPolicy', { policyData: r, callback: this.getList });
            },
            // 点击查询置为第一页
            queryList () {
                // this.CustomerForm.pageNum = 1
                this.params = { ...this.CustomerForm }
                delete this.params.birthday
                for (let key in this.params) {
                    if (!this.params[key] || this.params[key] === '' || this.params[key].length === 0) {
                        delete this.params[key]
                    }
                }
                if (this.CustomerForm.birthday && this.CustomerForm.birthday.length === 2) {
                    this.params.birthdayStart = new Date(new Date(new Date(this.CustomerForm.birthday[0]).setHours(0)).setMinutes(0)).setSeconds(0)
                    this.params.birthdayEnd = new Date(new Date(new Date(this.CustomerForm.birthday[1]).setHours(0)).setMinutes(0)).setSeconds(0) + 24 * 3600 * 1000
                }
                this.tableData = this.$filters(this.params, this.newData);
            },
            // 获取列表
            getList () {
                let cData = JSON.parse(localStorage.getItem('policyData'));
                if(!cData){
                    cData = [
                        {"index": "1","date": "2020-5-1 00:00:00","vCode": "LVSHJCAL8FE384344","safeType": "新车车险","safeName": "阳光保险","carType": "卡罗拉","region": "浙江省杭州市","status": "确认中"},
                        {"index": "2","date": "2020-5-1 00:00:00","vCode": "LVSHJCAL8FE384344","safeType": "续保","safeName": "平安保险","carType": "大众","region": "上海市黄浦区","status": "已开通"},
                        {"index": "3","date": "2020-5-1 00:00:00","vCode": "LVSHJCAL8FE384344","safeType": "新车车险","safeName": "阳光保险","carType": "卡罗拉","region": "浙江省杭州市","status": "确认中"},
                        {"index": "4","date": "2020-5-1 00:00:00","vCode": "LVSHJCAL8FE384344","safeType": "续保","safeName": "平安保险","carType": "大众","region": "上海市黄浦区","status": "已开通"},
                    ]
                }
                localStorage.setItem('policyData', JSON.stringify(cData));
                this.tableData = cData;
                this.newData = cData;
                // this.CustomerForm.pageNum = 1
                this.total = this.tableData.length;
            },
            // 重置表单
            reset () {
                this.CustomerForm = {
                    region: '',
                    carType: '',
                    safeName: '',
                    date1: '',
                }
                this.$nextTick(() => {
                    this.getList()
                })
            },
            exportFile () {
                if(this.CustomerForm.birthday[0] || this.CustomerForm.vCode != "" || this.CustomerForm.bsType !== "" || this.CustomerForm.bxType !== "" || this.CustomerForm.zjType !== ""){
                    this.$message({ type: 'success', message: `导出成功!` })
                }else{
                    this.$message.warning('请先选择筛选条件！')
                }
            },
            // 每页显示条数
            pageSizeChange (val) {
                let pages = Math.ceil(this.total / val)
                this.CustomerForm.pageSize = val
                this.params.pageSize = val
                if (this.CustomerForm.pageNum > pages) {
                    this.CustomerForm.pageNum = 1
                    this.params.pageNum = 1
                }
                this.queryList()
            },
            // 当前页码
            pageCurrentChange (val) {
                this.CustomerForm.pageNum = val
                this.params.pageNum = val
                this.queryList()
            }
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped rel="stylesheet/scss">

</style>
